<?php

namespace App\Admin\Controllers;

use App\Admin\Repositories\Student;
use Dcat\Admin\Form;
use Dcat\Admin\Grid;
use Dcat\Admin\Show;
use Dcat\Admin\Http\Controllers\AdminController;

class StudentController extends AdminController
{
    /**
     * Make a grid builder.
     *
     * @return Grid
     */
    protected function grid()
    {
        return Grid::make(new Student(['plan', 'project', 'invite']), function (Grid $grid) {
            $grid->column('id')->sortable();
            $grid->column('name');
            $grid->column('birthday');
            $grid->column('begin_control');
            $grid->column('invite.sales_id', '渠道ID');
            $grid->column('after_control');
            $grid->column('plan.name', '控涨方案');
            $grid->column('control_result');
            $grid->column('project.name', '今日项目');
            $grid->column('member_id');
            // $grid->column('card_id');
            // $grid->column('score');
            // $grid->column('sex');
            // $grid->column('phone');
            // $grid->column('money');
            // $grid->column('alias');
            // $grid->column('status');
            // $grid->column('type');
            // $grid->column('created_at');
            // $grid->column('updated_at')->sortable();
        
            $grid->filter(function (Grid\Filter $filter) {
                $filter->equal('id');
                $filter->equal('phone');
        
            });
        });
    }

    /**
     * Make a show builder.
     *
     * @param mixed $id
     *
     * @return Show
     */
    protected function detail($id)
    {
        return Show::make($id, new Student(), function (Show $show) {
            $show->field('id');
            $show->field('name');
            $show->field('birthday');
            $show->field('begin_control');
            $show->field('after_control');
            $show->field('control_plan');
            $show->field('control_result');
            $show->field('today_plan');
            $show->field('member_id');
            $show->field('card_id');
            $show->field('score');
            $show->field('sex');
            $show->field('phone');
            $show->field('money');
            $show->field('alias');
            $show->field('status');
            $show->field('type');
            $show->field('created_at');
            $show->field('updated_at');
        });
    }

    /**
     * Make a form builder.
     *
     * @return Form
     */
    protected function form()
    {
        return Form::make(new Student(), function (Form $form) {
            // $randomNumber = rand(1000, 9999);
            $form->display('id');
            $form->text('name');
            $form->number('sex')->options(formSexOptions())->rules('required')->default(0);
            $form->date('birthday')->format('YYYY-MM-DD');
            $form->text('phone')->rules('required');
            $form->number('begin_control')->default(30);
            $form->number('after_control')->default(300);
            $form->select('control_plan')->options('/api/plan')->rules('required');
            $form->select('control_result')->options(formResultOptions())->default(0)->rules('required');
            $form->select('today_plan')->options('/api/project')->rules('required');
            $form->text('member_id')->default(date('YmdHis'));
            $form->text('card_id')->default('-');
            $form->number('score')->default(0);
            $form->number('money')->default(0);
            $form->text('alias')->default('-');
            $form->select('status')->options(formStatusOptions())->default(1)->rules('required');
            $form->hidden('type')->default(0);
        
            $form->display('created_at');
            $form->display('updated_at');
        });
    }
}
